package demo.icanci.reflect;

import java.lang.reflect.Method;

/**
 * @author icanci
 * @date Created in 2021/02/05 00:19
 * @version 1.0
 */
public class MethodController {
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("demo.icanci.reflect.ReflectTarget");
        System.out.println("获取所有的共有方法");
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
        System.out.println("获取所有的方法");
        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
        }
        System.out.println("获取单个 ");
        Method show1 = clazz.getMethod("show1", String.class);
        System.out.println(show1);
        ReflectTarget o = (ReflectTarget)clazz.getConstructor().newInstance();
        show1.invoke(o,"hello???");

        Method show4 = clazz.getDeclaredMethod("show4", int.class);
        show4.setAccessible(true);
        show4.invoke(o,123);
    }
}
